﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace ClickScreen
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        List<System.Drawing.Point> pointList = new List<System.Drawing.Point>();

        private void SelectPoint_Click(object sender, RoutedEventArgs e)
        {
            pointList.Clear();

            MouseKeyHookHelper hookHelper = new MouseKeyHookHelper();
            hookHelper.SetMouseDownPointEvent += HookHelper_SetMouseDownPointEvent;
            hookHelper.InstallHookAsync();
        }

        private void HookHelper_SetMouseDownPointEvent(System.Drawing.Point obj)
        {
            pointList.Add(obj);
            clickLists.Text = string.Join(Environment.NewLine, pointList);
        }

        private void Start_Click(object sender, RoutedEventArgs e)
        {
            var clickTimess = 10;
            if (!string.IsNullOrEmpty(clickTimes.Text))
            {
                clickTimess = int.Parse(clickTimes.Text);
            }

            var clickOnceTimess = 1;
            if (!string.IsNullOrEmpty(clickOnceTimes.Text))
            {
                clickOnceTimess = int.Parse(clickOnceTimes.Text);
            }

            for (int i = 0; i < clickTimess; i++)
            {
                foreach (var item in pointList)
                {
                    var point = item;
                    AutoIt.AutoItX.MouseClick("LEFT", point.X, point.Y, clickOnceTimess, 10);
                }
            }
        }
    }
}
